<include file="StoreZT:header"/>
<div class="wraper">
    <div class="tab-box order-detail">
        <ul class="tab clearfix">
			<if condition="$picked eq 0">
				<li class="tab-list <if condition="!isset($status)">active</if>">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						全部
					</a>
				</li>
				<li class="tab-list <if condition="$status eq '21'">active</if>">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>21,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待付款
					</a>
				</li>

				<li class="tab-list <if condition="$status eq '1'">active</if>">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>1,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待发货
					</a>
				</li>
				<li class="tab-list <if condition="$status eq '2'">active</if>">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>2,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待收货
					</a>
				</li>
				<li class="tab-list <if condition="$status eq '3'">active</if>">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>3,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待评价
					</a>
				</li>
			<else />
				<li class="tab-list <if condition="!isset($status)">active</if>" style="width:25%;">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						全部
					</a>
				</li>
				<li class="tab-list <if condition="$status eq '21'">active</if>" style="width:25%;">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>21,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待付款
					</a>
				</li>
				<li class="tab-list <if condition="$status eq '1'">active</if>" style="width:25%;">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>1,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待提货
					</a>
				</li>
				<li class="tab-list <if condition="$status eq '3'">active</if>" style="width:25%;">
					<a href="{BEESCRM::U('base/storeZT/orderlist',array('status'=>3,'store_id'=>$storeId,'origin'=>$origin,'picked'=>$picked))}"/>
						待评价
					</a>
				</li>
			</if>
        </ul>
        <volist name="data" id="vo">
	        <div class="order-list">
	            <p class="order-num">
	            	订单号：{BEESCRM:$vo.order_sn}
	            </p>
	            <volist name="vo['StoreOrderGoods']" id="v" key="k">
					<if condition="$vo['status'] eq 0">
						<a href="{BEESCRM:$vo.url}" class="list-info order text-black">
					<else/>
						<a href="{BEESCRM::U('base/storeZT/order',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="list-info order text-black">
					</if>
						<div class="product-img tb-cell">
							<div><img src="{BEESCRM:$v.goods_thumb}"></div>
						</div>
		                <div class="product-info">
		                    <p>{BEESCRM:$v.goods_name}</p>
		                    <if condition="$k eq 1">
		                    <p class="pull-right">
			            		<switch name="vo['status']">
			            			<case value="0" break="1">待付款</case>
			            			<case value="1" break="1">
										<if condition="$v.picked eq 1">
											待提货
										<else/>
											待发货
										</if>
									</case>
			            			<case value="2" break="1">待收货</case>
			            			<case value="3" break="1">待评价</case>
			            			<case value="4" break="1">已完成</case>
			            			<case value="5" break="1">
			            				<if condition="$vo['api_refund_status']">
		            						系统退款中
		            					<else/>
		            						申请退款
		            					</if>
			            			</case>
			            			<case value="6" break="1">退款成功</case>
			            			<case value="7" break="1">已关闭</case>
			            			<case value="8" break="1">已取消</case>
			            		</switch>
			            	</p>
			            	</if>
		                    <p class="prize"><span>￥{BEESCRM:$v.goods_price}</span> <span>X{BEESCRM:$v.goods_num}</span></p>
							<p class="text-12">
								<if condition="$v.discount gt 0">
									<span class="product-label label-bg-red">{BEESCRM:$v.discount}折</span>
								</if>
								<span class="product-label"><if condition="$v.picked eq 1">自提<else/>快递</if></span>
								<if condition="$store_type eq 2">
									<if condition="$v.pay_alipay_id neq $alipayId"><span class="product-label">厂家直营</span></if>
								<else />
									<if condition="$v.pay_wechat_id neq $wechatId"><span class="product-label">厂家直营</span></if>
								</if>
							</p>
		                    <if condition="$v['spec_1'] neq ''">
		                    <p>规格：{BEESCRM:$v['spec_1']} {BEESCRM:$v['spec_2']} {BEESCRM:$v['spec_3']}</p>
		                    </if>
		                </div>
					</a>
	            </volist>
	            <div class="amount"><span>共计{BEESCRM:$vo.StoreOrderGoods|count}件商品 合计：</span>￥{BEESCRM:$vo.order_amount}</div>
	            <switch name="vo['status']">
	            	<case value="0" break="1">
	            		<div class="btn-box">
			                <a href="javascript:void(0)" class="btn cancel-order" data-id="{BEESCRM:$vo.order_id}">取消订单</a>
			                <a href="{BEESCRM:$vo.url}" class="btn pay pay-immediately">立即付款</a>
			            </div>
	            	</case>
	            	<case value="1" break="1">
	            		<div class="btn-box">
                			<if condition="$vo.picked eq 1">
								<a href="{BEESCRM::U('base/storeZT/billOfLading',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="btn">提货单</a>
								<a href="{BEESCRM::U('base/storeZT/order',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="btn">查看详情</a>
							<else/>
								<a href="{BEESCRM::U('base/storeZT/order',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="btn">查看详情</a>
							</if>
			            </div>
	            	</case>
	            	<case value="2" break="1">
	            		<div class="btn-box">
                			<a href="{BEESCRM::U('base/storeZT/order',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="btn">查看详情</a>
			                <a href="javascript:void(0)" class="btn confirm-receive" data-id="{BEESCRM:$vo.order_id}">确认收货</a>
			            </div>
	            	</case>
	            	<case value="3" break="1">
	            		<div class="btn-box">
                			<a href="{BEESCRM::U('base/storeZT/order',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="btn">马上评价</a>
			            </div>
	            	</case>
	            	<case value="4|5|6|7|8" break="1">
	            		<div class="btn-box">
                			<a href="{BEESCRM::U('base/storeZT/order',array('store_id'=>$storeId,'origin'=>$origin,'order_id'=>$vo['order_id']))}" class="btn">查看详情</a>
			            </div>
	            	</case>
	            </switch>
	        </div>
	    </volist>
    </div>
    <if condition="$data neq null"><div class="data-loding" style="display:none">数据加载中……</div></if>
</div>
<include file="StoreZT:commonJs" />
<input id="order_id" type="hidden">
<script type="text/javascript">

	$(function(){
		//取消订单
		$(document).on('click','.cancel-order',function(){
			var order_id=$(this).data('id');
			$('#order_id').val(order_id);
			$.confirm('确认取消订单吗？', toCancel);
		});

		function toCancel(){
			var order_id = $('#order_id').val();
			var store_id={BEESCRM:$storeId};
			var json={};
			json.url='/base/storeZT/cancelorder/order_id/'+order_id+'/store_id/'+store_id;
			$.getAjax(json,true,reload);
		}
		
		//确认收货
		$(document).on('click','.confirm-receive',function(){
			var order_id=$(this).data('id');
			var store_id={BEESCRM:$storeId};
			var json={};
			json.url='/base/storeZT/confirmreceive/order_id/'+order_id+'/store_id/'+store_id;
			$.getAjax(json,true,setTimeout(function(){
				var url = '/base/storeZT/order/order_id/'+order_id+'/store_id/'+store_id;
				location.href = url;
			},3000),'');
		});
		
		
		
		function reload(){
			setTimeout('location.reload()',3000);
		}
	});
	
	$(document).ready(function(){
        var page = 2,
       		url="{BEESCRM:$url}",
                flag = true;

        $(window).scroll(function(){
            if(($(window).scrollTop() + $(window).height() > $(document).height() - 40)){
                    if(flag) {
                        flag = false;
                        $.ajax({
                            type:"GET",
                            url:url,
                            data:{'page': page},
                            dataType:'json',
                            beforeSend:function(){
                            	// 显示加载时候的提示
                                $('.data-loding').show();
                            },
                            success:function(data){
                                var str ='';
                                var goods='';
                                if(data.status=='S'){
                                	$('.data-loding').hide();
                                    if(data.data.length > 0) {
                                        $.each(data.data,function(i,k){
                                        	var status = "<span class='pull-right'>"+k.status+"</span>";
                                        	$.each(k.StoreOrderGoods,function(x,y){
												goods+="<a href='"+ k.url +"' class='list-info order text-black'><div class='product-img tb-cell'><div><img src='"+y.goods_thumb+"'></div></div><div class='product-info'>"+
													" <p>"+y.goods_name+"</p>";
												if(x == 0){
													goods += status;
												}
												goods += "<p class='prize'><span>￥"+y.goods_price+"</span><span>X"+y.goods_num+"</span></p>";

												goods+="<p class='text-12'>";
												if (y.discount > 0){
													goods+="<span class='product-label label-bg-red'>"+y.discount+"折</span>";
												}
												goods+="<span class='product-label'>";
												if (y.picked == 1){
													goods+="自提";
												}else{
													goods+="快递";
												}
												goods+="</span>";
												$store_type = "{BEESCRM:$store_type}";
												if($store_type == 2){
													if (y.pay_alipay_id != data.alipay_id){
														goods+="<span class='product-label'>厂家直营</span>";
													}
												} else {
													if (y.pay_wechat_id != data.wechat_id){
														goods+="<span class='product-label'>厂家直营</span>";
													}
												}
												goods+="</p>";

												if(y.goods_spec_id != '') {
													goods += "<p>规格：" + y.spec_1 + y.spec_2 + y.spec_3 + "</p></div></a>";
												}
	                         				});
	                         				str += "<div class='order-list'><p class='order-num'>订单号："+k.order_sn+"</p>"+
											goods+"<div class='amount'><span>共计"+k.goods_count+"件商品 合计：</span>￥"+k.order_amount+"</div>"+k.statusInfo+"</div>";
	                         				goods='';
                                        });
                                        $(".order-detail").append(str);
                                        page++;

                                    } else {
                                        $('.data-loding').hide();
                                    }
                                    flag = true;
                                }
                            }
                        });
                    }
            }
        })
    })
</script>
<include file="StoreZT:footer" />